package com.tian.view.anim.custom

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.Animation
import androidx.fragment.app.Fragment
import com.tian.view.databinding.FragmentCustomAnim3dBinding

/**
 * @author tiansongtao
 * @date 2023/4/10 9:28
 */
class Rotate3DAnimFragment: Fragment() {

    private lateinit var b: FragmentCustomAnim3dBinding

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        b = FragmentCustomAnim3dBinding.inflate(inflater, container, false)
        return b.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        b.btTest.setOnClickListener {
            val anim = Rotate3dAnimation(0f, 90f, true)
            anim.duration = 2000
            anim.fillAfter = true
            anim.interpolator = AccelerateDecelerateInterpolator()
            anim.setAnimationListener(object : Animation.AnimationListener{
                override fun onAnimationStart(animation: Animation?) {

                }

                override fun onAnimationEnd(animation: Animation?) {
                    val anim1 = Rotate3dAnimation(90f, 180f, true)
                    anim1.duration = 2000
                    anim1.fillAfter = true
                    anim1.interpolator = AccelerateDecelerateInterpolator()
                    b.ivShow.startAnimation(anim1)
                }

                override fun onAnimationRepeat(animation: Animation?) {
                }

            })
            b.ivShow.startAnimation(anim)
        }
    }
}